﻿using System.Threading.Tasks;
using Grpc.Core;
using K9Admin.Remoting;
using K9Nano.Web.Accounts;

namespace K9Nano.Admin.Roles
{
    public class ApiResourceServiceImpl: ApiResourceService.ApiResourceServiceBase
    {
        protected readonly IRoleCurdAppService RoleCurdAppService;

        public ApiResourceServiceImpl(IRoleCurdAppService roleCurdAppService)
        {
            RoleCurdAppService = roleCurdAppService;
        }

        public override async Task<GetRolesInResourceReply> GetRolesInResource(GetRolesInResourceRequest request, ServerCallContext context)
        {
            var roles = await RoleCurdAppService.GetRolesInResourceAsync(request.Api, request.Resource,
                context.CancellationToken);
            var result = new GetRolesInResourceReply();
            result.Roles.AddRange(roles);
            return result;
        }
    }
}